﻿using System;
using System.Web;
using System.Web.UI;
namespace MSVSTS.Common
{
    public class JavaScript
    {
        const string MSG_ALERT = "<script>alert('{0}')</script>";
        const string TEXTCLEAR = "<script>TextClear();</script>";
        const string WINOPEN_URL = "<script>window.open('{0}','','{1}');location.href = '{2}'</script>";
        const string WINOPEN = "<script>window.open('{0}','','{1}')</script>";
        const string JAVASCRIPT = "<script language=\"javascript\">{0}</script>";
        const string REDIRECT = "<script language=\"javascript\">window.location='{0}'</script>";
        /// <summary>
        /// 在指定页面注册JS脚本，弹出消息。
        /// </summary>
        /// <param name="p"></param>
        /// <param name="message"></param>
        public static void Alert(Page p, string message)
        {
            Guid tmpid = Guid.NewGuid();
            p.ClientScript.RegisterStartupScript(typeof(string), tmpid.ToString(), string.Format(MSG_ALERT, message));
        }
        /// <summary>
        /// Response.Write (JavaScript 脚本)
        /// </summary>
        /// <param name="js">js脚本</param>
        public static void WriteJs(String js)
        {
            HttpContext.Current.Response.Write("<script langauge='JavaScript'>" + js + "</" + "script>");
        }
    }
}
